package com.example.springboot.controller.whritenameform;



import com.czk.annotation.DoDoor;
import com.example.springboot.config.mysql.UseDataSource;
import com.example.springboot.dao.UserRepository;
import com.example.springboot.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Optional;

/**
 * springboot中间件开发之白名单
 *
 * @Author:ChenZhangKun
 * @Date: 2021/8/9 11:58
 */
@RestController
@RequestMapping("/door")
public class WhiteNameFormController {
    @Autowired
    private UserRepository userRepository;
    @UseDataSource("alibaba")
    @DoDoor(key = "userId", returnJson = "{\"code\":\"1111\",\"info\":\"非白名单可访问用户拦截！\"}")
    @GetMapping("/get/{userId}")
    public User queryUser(@PathVariable("userId") Integer userId) {
        Optional<User> optional = userRepository.findById(userId);
        return optional.get();
    }
}
